package com.iflyings.android.convention

import com.android.build.api.dsl.LibraryExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType

internal fun Project.configureAndroidLibrary(commonExtension: LibraryExtension) {

    val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

    commonExtension.apply {

        compileSdk = libs.findVersion("compileSdkVersion").get().toString().toInt()

        defaultConfig {
            minSdk = libs.findVersion("minSdkVersion").get().toString().toInt()
            targetSdk = libs.findVersion("targetSdkVersion").get().toString().toInt()

            testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
            consumerProguardFile("consumer-rules.pro")
        }

        buildTypes {
            release {
                isMinifyEnabled = false //混淆
                proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
            }
        }
    }

    dependencies {
        add("implementation", libs.findBundle("androidx").get())
        add("testImplementation", libs.findLibrary("junit").get())
        add("androidTestImplementation", libs.findBundle("test-androidx").get())
    }
}